import { useState } from 'react'

export const useArray = <T>(initialArray: T[]) => {
  const [value, setValue] = useState(initialArray)
  const clear = () => {
    setValue([])
  }
  const removeIndex = (idx: number) => {
    setValue(value.filter((item, index) => index !== idx))
  }
  const add = (item: T) => {
    setValue([...value, item])
  }
  return { value, clear, removeIndex, add }
}
